package com.ytktt.study.week11.task4;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.TimeUnit;

/**
 * cache测试
 *
 * @author ytk
 */
@Slf4j
public class CacheApplication {

    public static void main(String[] args) throws InterruptedException {
        Cache<String, String> cache = new Cache<>(4, TimeUnit.SECONDS);
        cache.put("kty1", "123");
        Thread.sleep(3000L);
        cache.put("kty2", "234");
        Thread.sleep(2000L);
        cache.put("kty3", "345");
        Thread.sleep(1000L);
        cache.put("kty4", "456");
        Thread.sleep(500L);

        String kty1 = cache.get("kty1");
        String kty2 = cache.get("kty2");
        String kty3 = cache.get("kty3");
        String kty4 = cache.get("kty4");

        log.info("kty1 is null ? {}", kty1 == null);
        log.info("kty2 is null ? {}", kty2 == null);
        log.info("kty3 is null ? {}", kty3 == null);
        log.info("kty4 is null ? {}", kty4 == null);

        cache.destroy();
    }
}
